Refactor empty dir check