Make sure cursor is reset before calling event handlers, misc. formatting