clean main function - move filter logic into function