refactor, changed to write out json