Started major refactoring to make code more readable and maintainable