Used more proper function to check if directory exists