code clean up, removed global var and located relivent components in like
future bug consideration