outsource template code
parse parameters, minor code changes