Changes applied from marta's team/marta/astobj2 branch to solve a race condition