Adding event handling, small improvements