small optimization to previous answer