turned parse code into a function