Add debug and fix casting error.