lot more code for filtering and generating