completed code for filtering sequences, pardon my sloppy code towards the end