fixing the bug for stats and encoding