refactored uniq and reduce space