devide the main module and add  code into functions