Created functions for Main Script

Compartmentalized individual scripts into functions to improve
readability and organization
Check on this