Refactor dirFromPos