only moved function
improved test for refcount wrap around

who knows, it might be a negative value by now