moved negative log likelihood to function