Using when rather than if