Perfectioned pwd function