Refactored the GenerateMoves func