Add pre save hook, and basic middleware function.