Started refactoring the code