a bit of a refactor