Move some logic from header