Code adapted to some changes from Crossdata