Improve handlebars code

One bugfix (of a bug I introduced) and some code style cleanup.