quite a few changes, everything seems to work but not tested