Changes of sync() function, bug fixes.