Refactor on exceptions and error managment