adjust config.m4
add debug flag
refactor duplicated functions