Port of https://github.com/cerc-io/go-ethereum/pull/399 and https://github.com/cerc-io/go-ethereum/pull/397. Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com> Reviewed-on: #8