added batch mode, lots of code optimizations as well...