JS refactory