Added check if directory exists before removing it