Added directory option and modified code.