Rearranged code to be inside the Update function.