Fixed the issue with clearing and inserting into the database