moved some functions from extern to static.