It's much easier to read the code and follow the logic when code blocks within brackets are indented (and most code editors do it for you automagically). A lot of code blocks in the TPL file are only indented a single space from the "outer" code, which is not quite enough to make the indenting obvious. I suggest using a 2-space indent in the future (as well as fixing the 1-space indents as time allows). Also, if you use tabs for indenting, make sure the editor converts these to (2) spaces when the file is saved.
It's much easier to read the code and follow the logic when code blocks within brackets are indented (and most code editors do it for you automagically). A lot of code blocks in the TPL file are only indented a single space from the "outer" code, which is not quite enough to make the indenting obvious. I suggest using a 2-space indent in the future (as well as fixing the 1-space indents as time allows). Also, if you use tabs for indenting, make sure the editor converts these to (2) spaces when the file is saved.