Nowitzki agrees to three-year, $30 million with Mavs