Slight optimizations, needs a bunch of cleanup.