fixed bugs in event loop + fixed dialog bugs