more refactoring, left to output to json