Fixed a number of errors, now to write tests