Moved all GUI elements to main loop.
Renamed private functions.
Moved public functions to top of file.