handle function in more general way