refactor much of the hodge-podge code into their own files