Fixed out of bounds bug, added a test or two