added tests for edge cases and fix #8