Fix some errors in validity check