Factor out split_by_space functionality