Ntheory improvements

I've documented all changes in the commit logs.

@thilinarmtb --- let me know if you are ok with these changes.