added count and some bugfixes