Restructured main_hook