Clean up

Organized main.c into functions for better readability.