better handling for trailing spaces