Restructured generate key method (created removeRepeats() method)