improved hamming solution