Fix compiling errors of #3070

As the title said and add change more functions to be const.