Began refactoring the update_logic function