Refactoring for better architecture