refactored and added some tests. still have lots of tests to add.