Refactor the listing of files