Grabbed a chunk of code out of citserver.c cmd_term() and used it to create