added several func and diviede main func.