main function works up to generating structs for each piece; fixed closing of loop