moved external code to hook