moving parsing code to a function