refactored hamming distance function again