Added Service layer and refactored code