Adapted to newest libs
Comments, refactoring, minor changes