clean up error messages and nil handling