Fix bugs and add direction prediction for CTX