fixed getindex function