add order API and refactor code.