fix NPE
fix jshint warnings, move compaction to an interval