Re-structured code, added sorting and more generic filter for easier testing.