Extract some methods to functions to aid in testing