Modified implementation of pull request jbrien#18

* Fixes crash when a new variant is created