first fully working version

... there might be some bugs left, but did not find one at present