Do some refactoring of forked code and adding sync API