Split code into functions