Fix: issues with header and close function