Moved more stuff out of main into utils