-main function fix & refactoring