refactor: use indexOf instead of nested forEach