Rewritten the pushDir function