Refactor serial init to function
Refactored db initialization to function
Refactored data collection to function
Refactored startup code to main function