Moved code to clarify order of updates. Tried to get correct update order.