added code for vertical events
cleaned up the code