pattern improvements, delete trigger, cleanup and refactoring