remove const_cast and add const in a few places