VERSION WITH LEGAL MOVES. QUESTIONABLY IMPLEMENTED