Refactors the code and avoids double indexation