necessary changes made to avoid locking. debugging required