fixing wrong indexing