Implementing sorting of starred messages. Code refactoring.