Fixed some errors, added some tests (more to come)