counter now writes to database