reorder functions for easier finding
Reorder functions and cleanup
major cleanup and refactor