added tests and fixed some errors