Wrapped variables in quotes where appropriate, numerous fixes were
made, and errors now produce error messages and then exit with a
failed state