Refactored using strategy pattern