Added basic filtering and some bugfixes.