separate main and functions