added file and directory checks