Refine API and implementation