Refactored out json formatting code. #64