[WIP] Fix ref counting

targets #479
oops