Better way to manage errors