[Ellint Pi] Fix corner cases identified by Rocco Romeo and add tests for them.