Rearranged code

Visually splitted the code into main functions, GUI functions and GUI
creation