move dirname outside