moved everything into functions