Refactored to put global variables inside closures and immediately invoke the parse methods and the closure methods