Code updated to a more OOP friendly structure. General optimizations.