Add inline code hooks and refactored duplicated functions with cacro
rewrite register hooks with c macro.