Updated to handle empty pieces list.