Finally seem to have resolved the unit resetting issue and in the process have consolidated the code which was being used from 3 or 4 different triggers into a single function