added directorymaking function, fixed bugs