some refactoring with an eye on testing, innital testing draft