updated with duplicate counting

doesn’t seem to function properly