Change definition of function and still it has some problems