added an error formatting function and modified handeling rpc requests