This makes nicer the handling of layers in case of errors

I knew there was something wrong... :P