bit of refactoring as per David's request.