Adapted for better concurrency handling