Made modifications to make plugin functions more reliable