Refactored the error handle into the env struct