Bug fix: Added output buffering