Did some refactoring and added basic filtering.