Add in exception for bad casting, plus some comments
Minor formatting changes & comments