[JS] Rework clean up code based on feedback