Working version with lapack