refactored solution about split strings problem