Added hook to cater for AFM-68, plus monster patch with refactoring.