Indexing bug fixed
Formatting and error added
Fix last generated line bug.

The last generated line for checkbox_mutex is fixed at the end of the function, but it used the last value of a variable that was set in a loop to regenerate the name, which was not necessarily the last value that actually generated a line.