Moved ssm ready outside the loop for performance improvement