Refactoring; Adding CSV formatting for query results.