Architecture refactoring, bug fixing