Separated code into functions