Bug fixes and output formatting