Refactoring and adding sync