change macro into a function, remove unused code.