Separating dir code into functions