updated _cmd_function

Newly improved to correct a possible memory leak, as well as add in some future logging.