Message processing more robust

Many methods could not handle edge cases, mainly empty list of
messages. Added checks to message list length and guards against
dividing by zero.
A few test cases for message processing

Not much, but enough to help catch a few bugs from the previous commit.