code cleanup, add autoconf support