Relax syntactic constraint
Fix loop optimization and add testcase