Changed some variables names and improved locking efficiency