update to trim trailing space from templates as well