Fixed some errors, added new tests