refactored listener