better error checking (issue #1) and added exit status (issue #2)