Major refactoring, no more global vars, added options to turn on/off progress bars.