Added null check (defensive coding)