used the code given by christoph.
some little fixes.