a version where pmodes are generated only once, to be improved