a lil bit bug fix to test cases.
Optimizations, unsetting unnecessary variables.