Moved the BeforeSave handler function