Rewrite entirely for optimization purposes.