Added condition to remove the last piece