Adding function to get previous message. Fixing bug when getting next message.