added better closure support and logging