Fix bug in tidy function duplicating entries