Replaced nlm with optim function for fitting null. Should be more robust when there's less data.