Refactor based on Chris's suggestions
Refactor tests a bit more