fixed bugs and added tests for edit distance calculation