extracting method from main.