Changed .lock() and .unlock() to guards, mutex to spinlock. Added test environment