Added IO helper functions, moved program loop to C