Added some input paramter error checking.