This code is really crap since it was my first experience in PM programming :-)
Anyway, I included it here for completness - DONT USE it as an example of PM
programming, its ugly :-)

