improved batch inserting to db, added counter