Implemented ties. Improved AI generation.