Fixed some bugs and tests. Still broken.