Updating this method to be an iterator would remove the need to have to check if the current character is still valid when looping over characters.