minor editing pass
move import to top.
use scalar math functions for scalars.