Cleanup Gui's code.
Added some event handlers.