caught null pointer exceptions and an off by one error