move this earlier just after "var current ="...