code cleanup

make some function and structure defintion as local