added critical section stuff and moved code into namespace desm