Added null checks for intent and action