Remove redundant entries and spaces