fixed a bug on function