stats mode function: minor changes + unit test