re-orignize func in main