Cleaned up the filter_length function