can we extract all of this into methods, so its easy to stub?