Refactor Hamming