Moved a few functions and console logging.
Cleanup and refactor.