Corrected issues with undefined pieces variable