Enhancement and refactoring

- Service controller to reflect state change when a listener is added for the first time.
- Application master will shutdown itself when all containers are completed and no more pending requests
- Some code refactoring.