slightly neater solution