Updated to write the results straight to postgresql