rewritten for stud.ip >= 3.0; lost a lot of clutter