Working event loop. Main invocation fixed.