Refactored for increased modularity