Cleanup SQL submission code