Use SQLAlchemy instead of processes.
Add global counter, remove old code.