Refactored to chain of responsibilities pattern.