Refactor splitting string into chunks