Refactor stuff out of GUI