Refactored some GUI code, implemented tab closing.