BUG: trim function was not handling special cases leading to crash on Windows