adapted to new functions from Marco