Added metrics and numerous bug fixes.