Fix checking bounds of array index after using it; improper sizeof