Merge "More fixes towards the race conditions in AMS" into pi-dev