added tests and fixes #131