Fixed premature sql inserts