Refactored to make all database write operations non-blocking