normalize elevation values to positive numbers.
some restructure and comments