reorganizing code to make scalable