remove duplicate pieces and cleanup padding