Refactory js