tons of bugfixes for sync function