finish up refactoring and commenting
make tests conform