Finished code for updating local database with remote changes