Add more testing and fix some bugs.