Bug fixes for LAPACK calls and index permuting