Added some nilchecks. Broke expcurve out into its own function.