reimplment ls with fewer segfaults