Cleaned up some event handling