Code modification and added mouse events