debug mode now writes to the database at every iteration