removed locking
added some logic