refactored update to make it easier to read