added filtering logic back in. cleaned up a bit too.