Huge codebase refactoring and changes

Reshuffled code into better layout. Moved towards using better design
patterns