added the nested code for AMS