fix: movement within border underflow of unsigned integer
refactor: move direction functions to separate module