slight refactor and stuff to allow for testability