Refactoring subject-pool-index Javascript