Added returns to terminate functions on error.