Optimised the dat download and db insert queries