Fixed some bugs and discovered some new ones.