move parsing code to function