Turning loop that processes input rows into its own function.