Improvements regarding to errors handling

Improvements to raise errors according to JsonRPC 2.0 format, and also some clean-ups of code