separated main() into smaller functions