fixed bug in indexed code