extracted parsing code into its own function