added tests. Fixed bug