Fix a few RPC corner cases and add tests

There were just a few corner-cases about the place which could cause an internal server error when they should instead work.