Moved chunk tile index calculations to function