Remove some unused code and move some funtions to other files to make them static.