cleanups, fixes and simplification of diffie hellman code