Refactory JS mostly done