fixed demo could not be build problem
changed index calculation to work with iOS8