Fix bugs found in test + cert