Move nodir listing handler to it's own function