Architecture refactor

Updated architecture and merged.