added a crapton of tests, fixed bugs found along the way