Lots of refactoring. Added named process metrics support and debug mode