refactoring and json generator