improve utility function