Some better error checking.