Corrected a few bugs and unit tests now all pass.