works. todo: speed, compare with old, clean up, make update queries