Better logging, fix some quoting problems, also add var.template