cleans up code. structure is more modular. uses mainloop().