dir.c logic seperated into functions