added output buffering