add event handling, clean code