Rebase sg

It'd be great if we can discuss about the threading usage here. It may lead to quite some issues later if we're not careful.