fix powermod problems, add test coverage
Merge branch 'invmod'