nearly working, but sometimes duplicates letters