Added performance optimizations and a fix to fix reverted capsule errore.