[api] remove duplicated code (hope to get an A now :)