refactoring: LegalMoves as global function