reorganizing logic to make more sense
removoing old code