need to fix indices of the function