getAndNullify function

Credits to Compra for thinking about this one.