Refactor show_post function