added some error handling; returns exit status 0 or 1