fixed repeated_element_in_square and is_valid