split out format functionality
further refactoring
improved logging