Added null reference check.