Move some loops up to be faster.