Several fixes and refactoring based in checking with JSON from clients.