refactor and debug detect_fct and draw_fct
merge fix