devide the more code into functions