Fixed major bugs for batch running