removed nmax variable
corrected unwrap process