fix bug with function