separate function and main