implemented concurrency check. Hope I've not made any mistake