Refactor architecture