Updated setup_hooks to work with output buffering