Modified script to reflect exit code accurately