[WIP] Added charge generation function and friends.

@bas-rustenburg take a look, much simplified.  
Thanks!  CC me?