fixed errors with inserting into db