fixed nested else statements properly
handle invalid template strings