added some tests and fixed some bugs fixes #2