added event loop .. a messy one .. :(