Extract common function from main file