added output buffering
updated version