reorganize API code (bug 940398)