simplified the code, combined logic and GUI