Fixed rpc calls and refactoring