refactored code using sorting of collections with misbehaving
comparators