fixed out of bounds and nullpointers