Improve whitespace stripping

Thanks @nocash