Refactor suggested by @zeeman