Simplified main loop, removed some comments