Add a bunch of exception and add semaphore locking