Refactoring Insert Query Callback Function