api tuning: more nesting, more local calculation