Attempts to fix the algorithm with frequency, but still doesn't work