Minor performance improvements and some code reduction.