Refactored to provide more modularity