removed use of trim function

replaced use of trim function with a check if the last char is a space