Fixed bug that would lead to out of bounds memory access