Fixes a possible out of bounds exception