Refactored isValidMove