Some fixes to potential issues and added functionality for batch script
Fix for the bash script.