fix reentrant locks problem + code cleanup

Signed-off-by: robin-jarry <robin@jarry.cc>