refactored for modularity