Fixing bugs in message previous and next functions.