Modularized output, refactoring

Making it ready for output formatting plugin API.