pretty much rewritten

still a few lines from the previous version are left :)