Checked null references and added documentation.