Fixed event listener issues, code cleanup.