Optimized returning values from unref function and get_n_pop function