Fixed the update function