Move code to main() function