fix global leaks
remove unused variables
fix style