Added metrics and fixed bugs.