Awful bug with SEGFAULT in json lib fixed!
minor refactoring