Reduced the scope of the shifts, as they are only used inside the inner
loop.