Refactored to follow the Command pattern.