Refactored code for multiple listeners