fix and improve trailing whitespace matching