fix implicit declarations. remove redundant variables. use -Wall -WError flags