Reduced code in onUpdate method so it is not so repetitive