refactored whole code added ~100 LOC. Finally divided into two
independent classes.