Fixes a Stack popped in wrong order error caused by refcounting