bug fixes

A bug fixed in endBatch method.
A bug fixed in invoke method.
Other minor changes.