more trimming and error recovery