update code for sync and logic for remainders