Fix some errors in the script, redo IF statement for sync