try to fix average reconstruction error NaN and performance issues.