finished refactoring; added some basic test

the basic tests indicate that things are at least partially working!