Before modifying dir algor'm