Moved index parsing to subroutine