Slightly tidied logic.