working code (at least for the cup sequence)