Made some improvements and adapted to the latest library changes.