Fix error validation and reduce codes