added safety checks and fallbacks to injection method