refine api and fix bug--forgot to copy input