remove trailing space, compute all detection at once