Refactor more stuff into its own file