Improve function injection to be more reliable, and always fallback if an exception occurs