refactoring + json fixes