Added null check to prevent crashing on paste.