added checks for existing, added creation of dirs