error writing to database - fixed