Infinite while loop in load_messages()