Refactored mari hook to use shared functionality from tk-mari engine