added onclick listener
refactoring