Added first RPC API and some refactoring.