Added comments, fixed an out of bounds memory access issue