Added sync and fixed a few bugs