Exit codes; Prevent infinite loops

Added exit code for shell script error handling; trimmed contents to
prevent infinite loops