Above is roughly correct. Add the `beforeClose` method but call `model.close()` instead of `model.off`.