Making ls() more robust