added output buffering to avoid header errors