added tests and fixed minor bug