Moved delimiter detection into its own function