fixed sql statements and saves almost all data