PF: add code valid check
PF: clean code