Adds Charmichael function. Performs minor refactoring.