Updated to use Tcl to do all the heavy lifting