refactoring listen method.