Refactor objects passed to onclick event handler