fix edge cases and list comparison