code more similar to the flow in book
mouse events