cleanup (unused variables, etc) + bugfixes