refactor api code struct, extremely simplified the code, and making implement a new api very easy.
Merge remote-tracking branch 'origin/master'