Fixed event type
Added memory handling, no leaks for now