Adapted to newest libs
Minor refactoring