Fix potential outofbounds error

Signed-off-by: Jonas Kalderstam <jonas@kalderstam.se>