Updated to build a certificate chain to a root (atleast one) and also not have loops in chains