Fix the problem with mode function