Refactoring codes and add Mouse click event