Refactored the code in preparation for a future feature.