created helper functions to convert from index to coordinates.