added trim function to tsmain.cpp