fix mathematical mistake
minor improvements
lemId as a primitive (Thierry)