Refactored to write to disk, added variable lamda_ex