Fixed some issues in script and added more informative output