refact api code to make it more clean

Change-Id: I4e520bd55c0a4b1df67bc8c68681437e71e310e6