Various changes to make message parsing more robust