performance improvements and a code simplifier