off by 1 causing a crash, never trust example code you find online