Added frequency as a parameter for functions instead of using the global variable