move output/formatting logic out of db where it didn't belong