modified trimCsp to work a little better