refactoring of event handling for mac, memory handling changed