Refactored sync.io, fixed various bug, also fixes #1