Break recognize_shapes into separate function