Added safe guards to some functions and . , .. to mkdir