better factoring and naming oof some of the code