added tests and fixed some of the code