Refactor along lines suggested by rob