reorganizing and removing some unnecessary old code