Fixed some bugs and pulled in tests.