check for duplicates earlier, a bit faster