Updated output, fixed out of bounds exception