please add some comments on what this does, just in case it needs to be tweaked later on

also: is this self-written code, or 'stolen' somewhere? that's important w.r.t. licensing...