Created utils function to manage errors