Refactoring, fixes and cleanup. Output presentation preparation.