Compiles but hits an off by one error when run