Fixed a few bugs. All but one test pass now.