changed lots of functions so that less repetition