Code cleanup and regex fix for "no repeats" error