Increased readability changes.

Big functions defined in header moved to cpp. And changes to find min
and max value.