refactored hamming