Starting major refactoring of code. Fixing architecture.