Move TTL callback handling to standalone function

For better performance