fix trailing whitespaces function