modulize code in a better way