Added some error management