Fixed the code for negative indexes to wrap around.