There is a call to sync() at the end of this function. Please explain how this query is correctly placed in this function, say in constrast to changing something in sync().