Adapted to newest libs, TODO
Adapted to newest libs
Use mutable instead of ugly const_cast