New LLCP function plus some memory management fixes