added udf with logging for debugging