Clean up some error handling code