add function to collapse spaces