Rewrite code api, not finished.
Rewrite code api, not finished.