error control improvement
refactoring & small code fixing