Add batching, fix bugs.