Support for api call counting in loops; refactored the xmansion