Finished tests

Finished tests, fixed a few bugs. Ready for pull request.