Fixed inserting to the database