refactoring getLegalMoves() method