refactoring bind events code