refactor most functions into utils, add test stubs