Fixed a few bugs so it now successfully runs with the provided test suite.