Minor code cleanup and optimizations for v1.3.