Added output buffering and exception improvement

Added output buffering and exception improvement