Refactoring to support listening.
Added more state checks in controller