BATCH-2007: Added unit tests and minor fixes to error conditions