Improve errors control

Clean unused code