Refactor main loop to make it easier to integrate mongolito as a transformation library in your program.