code refactoring - main