Rewrite some sync code