refactor space & punctuation handling