Refactored update method, small improvements in performance.