Re-introduced reference counting of variables.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>