Dof indices optimizations

This follows the discussion in #410