Fixes index out of bounds bugs.

These were latent until a check was inserted in the library methods.