Added event handler for the view dropdown menu and cleaned up some of the code