Fix bug of null pointers.
Move service package and related classes out of SDK.