Got a few bugs worked out and added a bunch of tests