Added click and double click events, minor code restucturing