Refactoring Error management + Some fixes