Code is refactored and simplified.