Fix some bugs. Sync still has some problems... be careful