refactor and changing output format