Fixes bug in event handler