Migrated server part to js, new sync (first attempt), minfixes