refactored to aid re-use