working version for multi certificate. Lacks docs