Some refactoring and callback error fix