Code cleanup
Adapted to newest libs