Started refactoring of code