Refactored GUI code a lot, hopefully easier to read