user defined function not working