optimizations, certificate verification, code cleanup