Refactured for simplicity