fixed bug in emit-sum. added testcases for optimize* and emit-code