Re-added event loop and fixed a few other major mistakes.