refactoring for better modularity/structure