Linked comment thread to posts when prev is clicked and cleaned up code