reorganize release funcs in order to make thread safe