adding lock/mutex and free directory