Refactor to be fractionally less nasty