more refactoring and output clean up to match csv format