Changed next message ID storage, added error handling if message ID is inconsistent (not tested)