Fixes out-of-bounds exception.