Added safe way of getting directory.