#27 Fix message processing algorithm