Miscellaneous error handling fixes