Avoid use of const_cast

Remove a const_cast that can cause thread safety problems in the multithreaded framework.