Added simple error checking for cex
Optimized nonce calculation