Implemented Locking

Has a timing bug/race condition