refactored code for onModelSet/Save. Moved to bbhook.