Modified to handle the case when the frequency input is a list