Added better error management