Various bugfixes, added scan counter