Refactored to be Cilex-compatible