Agent records more stats and code cleanup