fixed negative indexing bug