refactoring main to core