Simplify generated main_template; Add workaround for possible p.subrequest bug [fixes #9]