Added more performance counters and done some refactoring.