fix heavy javascript recursion bug