Wrote code for more rigorous loss likelihood calculation