Re-refactored solution