Oprimization to for dir() loop