Fixed a bug involving boundary collisions and an index-out-of-bounds error (my bad)