combined code that was doing the same thing